import groovy.text.SimpleTemplateEngine
import groovy.text.*
import java.io.*


class TemplateUtils
{
    static String readTemplateFile(String sourceFilePath)
    {
        return Utils.readFileLocalOrRemote(sourceFilePath)
    }

    static void writeResultFile(String text, String resultFilePath)
    {
        
        new File(resultFilePath).write(text)
    }

    static String getResultFromTemplate(templateText, binding)
    {
        String resultText

        def engine = new SimpleTemplateEngine()
        
        def result = engine.createTemplate(templateText).make(binding)

        resultText = result.toString()

        return resultText
    }
    
    static void main(args)
    {
        def templateText = 'Dear "$firstname $lastname",\nSo nice to meet you in <% print city %>.\nSee you in ${month},\n${signed}'

        def binding = ["firstname":"Sam", "lastname":"Pullara", "city":"San Francisco", "month":"December", "signed":"Groovy-Dev"]

        def result1 = getResultFromTemplate(templateText, binding)

        def result = 'Dear "Sam Pullara",\nSo nice to meet you in San Francisco.\nSee you in December,\nGroovy-Dev'

        assert result == result1
    }
}
